#include "StdAfx.h"
#include "CircleObj.h"


CCircleObj::CCircleObj(void):CShape()
{
	m_shapeStyle = SHAPE_CIRCLE;

	m_dblCenterX = 0.0;	
	m_dblCenterY = 0.0;	
	m_dblRadius = 0.0;	
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;
	m_dblFillColorR =0.0;
	m_dblFillColorG =0.0;
	m_dblFillColorB =0.0;
	m_bIsGradient=false;
	m_bIsCerter = false;
	m_bIsExternal = false;
	m_bIsInner = false;
}

CCircleObj::CCircleObj( CEntityObj* pParentEnt ):CShape(pParentEnt)
{
	m_shapeStyle = SHAPE_CIRCLE;

	m_dblCenterX = 0.0;	
	m_dblCenterY = 0.0;	
	m_dblRadius = 0.0;	
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;
	m_dblFillColorR =0.0;
	m_dblFillColorG =0.0;
	m_dblFillColorB =0.0;
	m_bIsGradient=false;
	m_bIsCerter = false;
	m_bIsExternal = false;
	m_bIsInner = false;
}

CCircleObj::CCircleObj(const CCircleObj* pSrc ):CShape(pSrc)
{
	m_shapeStyle = pSrc->getShapeStyle();

	m_dblCenterX = pSrc->GetCenterX();	
	m_dblCenterY = pSrc->GetCenterY();	
	m_dblRadius = pSrc->GetRadius();	
	m_dblR=pSrc->GetColorR();
	m_dblG=pSrc->GetColorG();
	m_dblB=pSrc->GetColorB();
	m_dblFillColorR =pSrc->GetFillColorR();
	m_dblFillColorG =pSrc->GetFillColorG();
	m_dblFillColorB =pSrc->GetFillColorB();
	m_bIsGradient=pSrc->GetIsGradient();
	m_bIsCerter = pSrc->GetIsCerter();
	m_bIsExternal = pSrc->GetIsExternal();
	m_listColorValue=pSrc->GetColorValueList();
	m_bIsInner = pSrc->GetIsInner();
}

CCircleObj::~CCircleObj(void)
{

}

void CCircleObj::Serialize( CArchive & ar )
{
	if (GetIsSvgGroundShape()||GetIsSvgComponentShape())
	{
		if (ar.IsStoring())
		{
			ar << m_dblCenterX;	
			ar << m_dblCenterY;	
			ar << m_dblRadius;
			ar<<m_dblR;
			ar<<m_dblG;
			ar<<m_dblB;
			ar<<m_dblFillColorR;
			ar<<m_dblFillColorG;
			ar<<m_dblFillColorB;
			ar<<m_bIsGradient;
			int nSize=m_listColorValue.size();
			ar<<nSize;
			std::list<float>::iterator it_value=m_listColorValue.begin();
			for (;it_value!=m_listColorValue.end();it_value++)
			{
				ar<<*it_value;
			}
			if (CObj::m_lFileVersion>78)
			{
				ar<<m_bIsCerter;
				ar<<m_bIsExternal;
			}
			if (CObj::m_lFileVersion>86)
			{
				ar<<m_bIsInner;
			}
		} 
		else
		{
			ar >> m_dblCenterX;	
			ar >> m_dblCenterY;	
			ar >> m_dblRadius;
			ar >>m_dblR;
			ar >>m_dblG;
			ar >>m_dblB;
			ar >>m_dblFillColorR;
			ar >>m_dblFillColorG;
			ar >>m_dblFillColorB;
			ar >>m_bIsGradient;
			int nSize=0;
			ar >>nSize;
			//std::list<float>::iterator it_value=m_listColorValue.begin();
			for (int i=0;i<nSize;i++)
			{
				float value=0.0;
				ar>>value;
				m_listColorValue.push_back(value);
			}
			if (CObj::m_lFileVersion>78)
			{
				ar>>m_bIsCerter;
				ar>>m_bIsExternal;
			}
			if (CObj::m_lFileVersion>86)
			{
				ar>>m_bIsInner;
			}
		}
	}
	CShape::Serialize(ar);
}


CDisplayObj * CCircleObj::CreateDisplayObj( long lLayerId )
{
	CCircleDisplayObj *pCircleDisplayObj = new CCircleDisplayObj(this);
	pCircleDisplayObj->SetLayerId(lLayerId);
	return pCircleDisplayObj;
}


void CCircleObj::CopyDisplayObj( long lSourceLayerId, long lDestLayerId )
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CCircleObj::DeleteDisplayObj( long lLayerId )
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}



void CCircleObj::CalcBox()
{	
	m_minX = m_dblCenterX-m_dblRadius;
	m_minY = m_dblCenterY-m_dblRadius;
	m_maxX = m_dblCenterX+m_dblRadius;
	m_maxY = m_dblCenterY+m_dblRadius;
}

void CCircleObj::SetFillColor( double colorR, double colorG, double colorB )
{
	m_dblFillColorR = colorR;
	m_dblFillColorG = colorG;
	m_dblFillColorB = colorB;
}

void CCircleObj::SetColor( double colorR, double colorG, double colorB )
{
	m_dblR = colorR;
	m_dblG = colorG;
	m_dblB = colorB;
}

CObj * CCircleObj::Clone() const
{
	return new CCircleObj(this);
}













